Imports System.Math

Public Class FGalaxyForm2

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

        If FGalaxyForm1.trace = 1 Then Debug.Print("Form2 PictureBox1.Click")

    End Sub
    Private Sub Picture_mousedoubleclick() Handles PictureBox1.MouseDoubleClick

        Dim ip As Long
        Dim power As Double
        ' Debug.Print("Form2 PictureBox1.MouseDoubleClick")
        ip = Val(FGalaxyForm1.TBpicture.Text)
        FGalaxyForm1.picture1 = ip
        ''Form1.Text1(1) = xp1          ' x1 %
        ''Form1.Text1(2) = yp1          ' y1 %
        ''Form1.Text1(3) = xp2          ' x2 %
        ''Form1.Text1(4) = yp2          ' y2 %

        power = 10 ^ 6
        Debug.Print("Form2 DblClick xp1" + Str(Int(FGalaxyForm1.xp1 * power) / power) + " xp2" + Str(Int(FGalaxyForm1.xp2 * power) / power) + " yp1" + Str(Int(FGalaxyForm1.yp1 * power) / power) + "yp2" + Str(Int(FGalaxyForm1.yp2 * power) / power) + " state " + Str(FGalaxyForm1.state))
        ' If state > 1 Then Square xp1, xp2, yp1, yp2

        ' Debug.Print "Form2 DblClick xp1"; Int(xp1 * power) / power; "xp2"; Int(xp2 * power) / power; "yp1"; Int(yp1 * power) / power; "yp2"; Int(yp2 * power) / power; "state "; state

        If FGalaxyForm1.state > 1 Then FGalaxyForm1.Main()

    End Sub
    Private Sub Form_mousedoubleclick() Handles PictureBox1.DoubleClick

        If FGalaxyForm1.trace = 1 Then Debug.Print("Form2 PictureBox1.DoubleClick")

    End Sub
    Private Sub Form_mousedown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown

        Dim mouseX As Integer = e.X
        Dim mouseY As Integer = e.Y
        Dim power As Long
        Dim xsave, ysave As Double

        FGalaxyForm1.GETScreen()
        ' MouseMove Event Example
        FGalaxyForm1.state = FGalaxyForm1.state + 1
        Debug.Print("Form2 PixtureBox1.Mousedown X" + Str(mouseX) + " y" + Str(mouseY) + " state " + Str(FGalaxyForm1.state))
        If FGalaxyForm1.xp1 = 0 Then
            FGalaxyForm1.xp1 = mouseX / FGalaxyForm1.xmax : FGalaxyForm1.yp1 = mouseY / FGalaxyForm1.ymax
        Else
            If FGalaxyForm1.xp2 = 1 Then
                FGalaxyForm1.xp2 = mouseX / FGalaxyForm1.xmax : FGalaxyForm1.yp2 = mouseY / FGalaxyForm1.ymax
                If Abs(FGalaxyForm1.xp2 - FGalaxyForm1.xp1) < 0.01 Or Abs(FGalaxyForm1.yp2 - FGalaxyForm1.yp1) < 0.01 Then
                    FGalaxyForm1.xp2 = 1 : FGalaxyForm1.yp2 = 1 : FGalaxyForm1.state = FGalaxyForm1.state - 1   ' ignore
                End If
            End If
        End If
        If FGalaxyForm1.xp2 < FGalaxyForm1.xp1 Then xsave = FGalaxyForm1.xp1 : FGalaxyForm1.xp1 = FGalaxyForm1.xp2 : FGalaxyForm1.xp2 = xsave
        If FGalaxyForm1.yp2 < FGalaxyForm1.yp1 Then ysave = FGalaxyForm1.yp1 : FGalaxyForm1.yp1 = FGalaxyForm1.yp2 : FGalaxyForm1.yp2 = ysave

        power = 10 ^ 6
        FGalaxyForm1.TBxp1.Text = Int(FGalaxyForm1.xp1 * power) / power          ' x1 %
        FGalaxyForm1.TByp1.Text = Int(FGalaxyForm1.yp1 * power) / power          ' y1 %
        FGalaxyForm1.TBxp2.Text = Int(FGalaxyForm1.xp2 * power) / power          ' x2 %
        FGalaxyForm1.TByp2.Text = Int(FGalaxyForm1.yp2 * power) / power          ' y2 %

        power = 10 ^ 6
        Debug.Print("Form2 PictureBox1.Mousedown xp1" + Str(Int(FGalaxyForm1.xp1 * power) / power) + " xp2" + Str(Int(FGalaxyForm1.xp2 * power) / power) + " yp1" + Str(Int(FGalaxyForm1.yp1 * power) / power) + " yp2" + Str(Int(FGalaxyForm1.yp2 * power) / power) + " state " + Str(FGalaxyForm1.state))

    End Sub
End Class